import java.util.*;

public class EventPush {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String input = scanner.nextLine();
        String R = input.substring(input.length() - 3, input.length());
        String[] rStrings = R.split("=");
        int r = Integer.parseInt(rStrings[1]);
        String content = input.substring(0, input.length() - 3);
        String[] abStrs = content.split("},");
        List<Integer> aList = new ArrayList<>();
        List<Integer> bList = new ArrayList<>();
        String[] cont = abStrs[0].split("=\\{");
        String[] en = cont[1].split(",");
        for (String e : en) {
            aList.add(Integer.parseInt(e));
        }
        cont = abStrs[1].split("=\\{");
        String[] en2 = cont[1].split(",");
        for (String e : en2) {
            bList.add(Integer.parseInt(e));
        }
        StringBuilder stringBuilder = new StringBuilder();
        for (int ai : aList) {
            for (int bi : bList) {
                if (ai < bi && bi - ai <= r) {
                    stringBuilder.append("(" + ai + "," + bi + ")");
                }
            }
        }
        System.out.println(stringBuilder.toString());
    }
}
